package com.hyl.config.websocket;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;

/**
 * socket配置类
 *
 * @author HYL
 * @create 2017-06-07 上午10:44
 **/
@Configuration
/*
* 开启使用STOMP协议来传输基于代理（message broker）的消息，
* 这个是时候使用@MessageMapping就相当于使用@RequestMapping
* */
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/endPointHyl")//注册协议的节点（endPoint），并映射指定的url
                .withSockJS();//使用SockJS协议
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {//配置消息代理
        registry.enableSimpleBroker("/topic");//广播式应配置一个/topic消息代理
    }

}
